/**
 * 
 */
package javavis.jip2d.functions.tia2012;

import java.io.FileOutputStream;
import java.io.Serializable;

import javavis.base.JIPException;
import javavis.jip2d.base.bitmaps.JIPBmpByte;
import javavis.jip2d.base.bitmaps.JIPBmpFloat;

/**
 * @author asc
 *
 */
public class Region implements Serializable {

	/**
	 * 
	 */
	private int P1x;
	private int P1y;
	private int P2x;
	private int P2y;
	
	/**
	 * @param i1
	 * @param j1
	 * @param i2
	 * @param j2
	 * @throws JIPException
	 */
	public Region(int i1, int j1, int i2,int j2) throws JIPException {
		P1x=i1;
		P1y=j1;
		P2x=i2;
		P2y=j2;
		//System.out.println(i1 + " " + j1 + " " + i2 + " " + j2 );
	}
	
	/**
	 * @param img
	 * @return
	 * @throws JIPException
	 */
	public float getValor(JIPBmpFloat img) throws JIPException
	{
		//Calcula el valor
		return ( -img.getPixelFloat(P1x,P2y) -img.getPixelFloat(P2x, P1y) + img.getPixelFloat(P2x,P2y) +img.getPixelFloat(P1x, P1y));
	}
	
	public float getValor(JIPBmpFloat img, int ancho, int alto) throws JIPException
    {
        //Calcula el valor
        return (-img.getPixelFloat(P1x+ancho,P2y+alto) -img.getPixelFloat(P2x+ancho, P1y+alto) + img.getPixelFloat(P2x+ancho,P2y+alto) + img.getPixelFloat(P1x+ancho, P1y+alto));
	    
    }

}
